from fastapi import APIRouter

from app.allsubdb.tools.models import Logs_Pydantic, Logs
from app.core.return_info import ReturnInfo, SUCCESS

router = APIRouter()


@router.get("/logs/hdfs/get_all")
async def read_notes():
    return_info = ReturnInfo()
    logs_all = await Logs_Pydantic.from_queryset(Logs.all())
    return_info.status = SUCCESS
    return_info.data = logs_all
    return return_info.todict()


@router.post("/logs/hdfs/insert")
async def create_note(log: Logs_Pydantic):
    return_info = ReturnInfo()
    logs_obj = await Logs.create(**log.dict(exclude_unset=True))
    return_info.status = SUCCESS
    return_info.data = logs_obj
    return return_info.todict()


@router.post("/logs/hdfs/update")
async def create_note(id: int, log: Logs_Pydantic):
    return_info = ReturnInfo()
    logs_obj = await Logs.filter(id=id).update(**log.dict(exclude_unset=True))
    return_info.status = SUCCESS
    return_info.data = logs_obj
    return return_info.todict()
